﻿package 
{
	import flash.events.Event;
	import flash.display.MovieClip;
	
	public class OverworldPlayer extends MovieClip 
	{
		private static const Speed:int = 5;
		private var lastX:int;
		private var lastY:int;
		private var PersonNumber:int;
		
		public function OverworldPlayer(playerNum:int) 
		{
			PersonNumber = playerNum;
			init();
		}
		
		private function init():void
		{
			lastX = x;
			lastY = y;
			holdFrame();
		}
		
		public function MoveFrame(moveDirection:int):void
		{
			switch(moveDirection)
			{
				case (1)://Down
					gotoAndStop(1);
				break;
				case (2)://Up
					gotoAndStop(2);
				break;
				case (3)://Right
					gotoAndStop(3);
				break;
				case (4)://Left
					gotoAndStop(4);
				break;
			}
			holdFrame();
		}
		
		public function Move(moveDirection:int):void
		{
			if (body != null)
			{
				body.play();
			}
			switch(moveDirection)
			{
				case (1)://Down
					y += Speed;
				break;
				case (2)://Up
					y -= Speed;
				break;
				case (3)://Right
					x += Speed;
				break;
				case (4)://Left
					x -= Speed;
				break;
			}
		}
		
		private function holdFrame():void
		{
			if (body != null)
			{
				if (body.larm != null)
				{
					body.larm.gotoAndStop(PersonNumber);
				}
				if (body.rarm != null)
				{
					body.rarm.gotoAndStop(PersonNumber);
				}
				if (body.rleg != null)
				{
					body.rleg.gotoAndStop(PersonNumber);
				}
				if (body.lleg != null)
				{
					body.lleg.gotoAndStop(PersonNumber);
				}
				if (body.body != null)
				{
					body.body.gotoAndStop(PersonNumber);
				}
				if (body.head != null)
				{
					body.head.gotoAndStop(PersonNumber);
				}
			}
		}
		
		public function CaptureXY():void
		{
			lastX = x;
			lastY = y;
		}
		
		public function StopPlayer():void
		{
			x = lastX;
			y = lastY;
		}
	}
}